home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FLLNGTH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  682 b   |  26 lines

  1. /* fileleng.c, from page 354 of Turbo C Bible */
  2. #include <stdio.h>
  3. main ()
  4. {
  5.    char filename [80];
  6.    FILE *infile;
  7.    long filesize;
  8.    printf ("Enter the name of an existing file: ");
  9.    gets (filename);
  10.                        /* Open the file */
  11.    if ((infile = fopen(filename, "r")) == NULL)
  12.    {
  13.         printf ("fopen failed to open: %s\n", filename);
  14.         exit (0);
  15.    }
  16.                    /* Get file size and display it. Use
  17.                    fileno to get the handle. */
  18.    if ((filesize == filelength (fileno (infile))) != -1L)
  19.    {
  20.         printf ("Size of %s = %ld bytes\n", filename, filesize);
  21.    }
  22.    else
  23.    {
  24.         printf ("Error getting file size\n");
  25.    }
  26. }